var currentLink = "";

$(document).ready(function() {
	var hash = location.hash;
	hash = hash.replace( /^#/, '' );
	if(hash != ''){
		if(hash.indexOf('/') != -1){
			hash = hash.split('/');
			showPage('?func=' + hash[0] + '&' + hash[1] + '&ajax=true');
		}
		else{showPage('?func=' + hash.replace( /^#/, '' ) + '&ajax=true');}
	}

	loadMsg();
});

$(window).hashchange( function(){
	if($('.modal.in').is(':visible')){
		$('.modal.in').modal('hide');
		setTimeout(function(){
			var hash = location.hash;
			hash = hash.replace( /^#/, '' );
			if(hash.indexOf('/') != -1){
				hash = hash.split('/');
				var first = hash.shift();
				var last = hash.join('%2F');
				showPage('?func=' + first + '&' + last + '&ajax=true');
			}
			else{showPage('?func=' + hash.replace( /^#/, '' ) + '&ajax=true');}
		},1000);
	}
	else{
		var hash = location.hash;
		hash = hash.replace( /^#/, '' );
		if(hash.indexOf('/') != -1){
			hash = hash.split('/');
			var first = hash.shift();
			var last = hash.join('%2F');
			showPage('?func=' + first + '&' + last + '&ajax=true');

			//hash = hash.split('/');
			//showPage('?func=' + hash[0] + '&' + hash[1] + '&ajax=true');
		}
		else{showPage('?func=' + hash.replace( /^#/, '' ) + '&ajax=true');}
	}
})

//$(".btn").click(function(e) {
//	var $this=$(this);
//    $this.attr('disabled','disabled');
//    setTimeout(function() {
//		$this.removeAttr('disabled');
//	}, 3000);
//});

function reload_page(){
	/*var hash = location.hash;
	hash = hash.replace( /^#/, '' );
	if(hash.indexOf('/') != -1){
		hash = hash.split('/');
		showPage('?func=' + hash[0] + '&' + hash[1] + '&ajax=true');
	}
	else{showPage('?func=' + hash.replace( /^#/, '' ) + '&ajax=true');}*/

	$(window).trigger('hashchange');
}

function formatCurrency(num) {
    var p = num.toFixed(2).split(".");
    return p[0].split("").reverse().reduce(function(acc, num, i, orig) {
        return  num + (i && !(i % 3) ? "," : "") + acc;
    }, "");
}

function showPage(u){
	$('.modal.in').modal('hide');
	$.ajax({
		type: "GET",
		url: u,
		beforeSend: function (xhr) {
			$("#show-content").block({
				message: 'Loading...',
				css: {
					border: 'none',
					padding: '15px',
					backgroundColor: '#000',
					'border-radius': '10px',
					'-webkit-border-radius': '10px',
					'-moz-border-radius': '10px',
					opacity: 0.8,
					color: '#fff'
				}
			});
			$("#show-content2").fadeOut();
		},
		success: function(msg){
			$("#show-content").unblock();
			currentLink = u;
			$("#show-content").html(msg).fadeIn();
		}
	});
}

function showPageIframe(u){
	currentLink = u;
	$("#show-content").html('<iframe src="'+u+'" frameborder="0" width="100%" height="80%" scrolling="no"></iframe').fadeIn();
}

function showContent(u){
	$.ajax({
		type: "GET",
		url: u,
		success: function(msg){
			$("#show-content2").html(msg).fadeIn();
		}
	});
}

function showPage2(u){
	$.ajax({
		type: "GET",
		url: u,
		success: function(msg){
			$("#show-content").html(msg).fadeIn();
		}
	});
}

function showMsg(id,msg){
	$("#"+id).html(msg).fadeIn();
	setTimeout(function(){ $("#"+id).fadeOut() },3000);
}

function toCurrency(number) {
    var number = number.toString(),
    dollars = number.split('.')[0],
    dollars = dollars.split('').reverse().join('')
        .replace(/(\d{3}(?!$))/g, '$1,')
        .split('').reverse().join('');
    return dollars;
}

function showMessage(msg){
	var a = msg.split("|");
	switch(a[0]){
		case '1':
			toastr.success(a[1]);
			break;
		case '2':
			toastr.error(a[1]);
			break;
		case '3':
			toastr.info(a[1]);
			break;
		case '4':
			toastr.warning(a[1]);
			break;
		default: toastr.info(a[1]);
	}
}

function showMessageJson(msg){
	var getData = $.parseJSON(msg);
	var typemsg = '';
	switch(getData.type){
		case 'success': toastr.success(getData.msg);break;
		case 'error': toastr.error(getData.msg);break;
		case 'notice': toastr.info(getData.msg);break;
		case 'warning': toastr.warning(getData.msg);break;
		default: toastr.info(getData.msg);
	}
}



function loadMsg(){
	$.ajax({
		type: "POST",
		url: "?func=usercp_ajax&ajax=true",
		data:{
			mod:"count_msg"
		},
		dataType: 'json',
		success: function(json){
			if(json.result){
				$("#noti_msg").addClass('noft-red').text(json.counter.message);
				$("#noti_warning").addClass('noft-red').text(json.counter.request);
			}
		}
	});
}

var auto_refresh = setInterval(loadMsg,60000);

function Login(){
	$.ajax({
		type: "POST",
		url: "?func=login&ajax=true",
		data: {
			username:$("#login-username").val(),
			password:$("#login-password").val(),
			remember:$("#remember:checked").val()
		},
		dataType: 'json',
		success: function(msg){
			if(msg.result){
				if(redirect_url != ''){
					window.location.href = redirect_url + '&token='+msg.token;
				}
				else{
					window.location.href = './';
				}
			}
			else{
				showMsg("displayMsg",msg.msg);
			}
		}
	});
}

function Logout(){
	$.ajax({
		type: "GET",
		url: "?func=logout&ajax=true",
		success: function(msg){
			$("#main-content").html(msg).fadeIn();
			window.location.reload();
		}
	});
}

function loadNotes(){
	$.ajax({
		type: "GET",
		url: "?func=note_list&ajax=true",
		success: function(msg){
			$("#listN").html(msg).fadeIn();
		}
	});
}

function openNotes(id){
	$.ajax({
		type: "GET",
		url: "?func=note_view&ajax=true&nid="+id,
		success: function(msg){
			$("#notes").html(msg).fadeIn();
		}
	});
}


function createNote(){
	$.ajax({
		type: "POST",
		url: "?func=note_create&ajax=true",
		data:{
			noteTitle:$("#noteTitle").val(),
			noteComment:$("#noteComment").val()
		},
		success: function(msg){
			showMessage(msg);
			loadNotes();
		}
	});
}

function createPType(){
	$.ajax({
		type: "POST",
		url: "?func=ptype_ajax&ajax=true",
		data:{
			mod:"type_create",
			type_name:$("#type_name").val()
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
			if(getData.type == 'success'){
				setTimeout(reload_page, 1000);
			}
		},
		complete: function(xhr){
			$("#type_create").modal('hide');
		}
	});
}

function deletePType(id){
	$.ajax({
		type: "POST",
		url: "?func=ptype_ajax&ajax=true",
		data:{
			mod:"type_delete",
			type_id:id
		},
		success: function(msg){
			showMessageJson(msg);
			reload_page();
		}
	});
}

function createTGroup(){
	$.ajax({
		type: "POST",
		url: "?func=ptype_ajax&ajax=true",
		data:{
			mod:"group_create",
			line_id:$("#type_group_create").val(),
			group_name:$("#group_name").val(),
			percent:$("#group_percent").val()
		},
		beforeSend: function(xhr){
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
			if(getData.type == 'success'){
				setTimeout(reload_page, 1000);
			}
			else{
				$('input[type=submit]').attr('disabled',false);
				$('button[type=submit]').attr('disabled',false);
			}
		},
		complete: function(xhr){
			$("#group_create").modal('hide');
		}
	});
}

function deleteTGroup(id){
	$.ajax({
		type: "POST",
		url: "?func=ptype_ajax&ajax=true",
		data:{
			mod:"group_delete",
			group_id:id
		},
		success: function(msg){
			showMessageJson(msg);
			reload_page();
		}
	});
}

function setTP(){
	$.ajax({
		type: "POST",
		url: "?func=dep_ajax&ajax=true",
		data: {
			setTP:"1",
			uid:$("#setTPid").val(),
			rid:$("#ridhid").val()
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				showPage('?func=dep_view&ajax=true&rid='+$("#ridhid").val());
			}
		}
	});
}

function doiTP(){
	$.ajax({
		type: "POST",
		url: "?func=dep_ajax&ajax=true",
		data: {
			doiTP:"1",
			uid:$("#doiTPid").val(),
			rid:$("#ridhid").val()
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				showPage('?func=dep_view&ajax=true&rid='+$("#ridhid").val());
			}
		}
	});
}

function taoPhongBan(){
	$.ajax({
		type: "POST",
		url: "?func=dep_create&ajax=true",
		data: {
			depName:$("#depName").val()
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			$('input[type=submit]').attr('disabled',false);
			$('button[type=submit]').attr('disabled',false);
			showMessage(msg);
			window.location.hash = 'dep_list';
		}
	});
}

function xoaPhongBan(id){
	$.ajax({
		type: "POST",
		url: "?func=dep_ajax&ajax=true",
		data: {
			room:$("#room"+id).val()
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){$("#row"+id).fadeOut("slow");}
		}
	});
}


/******** Nhan Vien ******/

function taoNhanVien(){
	$.ajax({
		type: "POST",
		url: "?func=user_create&ajax=true",
		data: {
			username:$("#username").val(),
			password:$("#password").val(),
			password2:$("#password2").val(),
			fullname:$("#fullname").val(),
			address:$("#address").val(),
			phonenumber:$("#phonenumber").val(),
			department:$("#department").val(),
			salary:$("#salary").val(),
			status:$("#status:checked").val()
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				window.location.hash = 'user_list';
			}
			else{
				$('input[type=submit]').attr('disabled',false);
				$('button[type=submit]').attr('disabled',false);
			}
		}
	});
}

function activeNV(id){
	$.ajax({
		type: "POST",
		url: "?func=user_ajax&ajax=true&uId="+id,
		data:{
			mod:"mActive"
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|",2);
			if(a[0]==1){
				showPage('?func=user_view&ajax=true&uId='+id);
			}
		}
	});
}

function blockNV(id){
	$.ajax({
		type: "POST",
		url: "?func=user_ajax&ajax=true&uId="+id,
		data:{
			mod:"mBlock"
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|",2);
			if(a[0]==1){
				showPage('?func=user_view&ajax=true&uId='+id);
			}
		}
	});
}

function deleteNV(id){
	$.ajax({
		type: "POST",
		url: "?func=user_ajax&ajax=true&uId="+id,
		data:{
			mod:"mDelete"
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|",2);
			if(a[0]==1){
				window.location.hash = 'user_list';
			}
		}
	});
}

function changePermission(id){
	var permissions = $("#permissionList").serialize();
	$.ajax({
		type: "POST",
		url: "?func=user_ajax&ajax=true&uId="+id,
		data: permissions,
		success: function(msg){
			showMessageJson(msg);
		}
	});
}

function changePermission2(id){
	var permissions = $("#permissionList2").serialize();
	$.ajax({
		type: "POST",
		url: "?func=user_ajax&ajax=true&uId="+id,
		data: permissions,
		success: function(msg){
			showMessageJson(msg);
		}
	});
}

function changeSalePermission(id){
	var permissions = $("#salePermissions").serialize();
	$.ajax({
		type: "POST",
		url: "?func=user_ajax&ajax=true&uId="+id,
		data: permissions,
		success: function(msg){
			showMessageJson(msg);
		}
	});
}

function changeLedPermission(id){
	var permissions = $("#ledPermissions").serialize();
	$.ajax({
		type: "POST",
		url: "?func=user_ajax&ajax=true&uId="+id,
		data: permissions,
		success: function(msg){
			showMessageJson(msg);
		}
	});
}

function changePermissionR(id){
	var permissions = $("#permissionList2").serialize();
	$.ajax({
		type: "POST",
		url: "?func=dep_ajax&ajax=true&rid="+id,
		data: permissions,
		success: function(msg){
			showMessageJson(msg);
		}
	});
}


function themGiahan(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			mRecei:$("#mRecei").val(),
			proStart:$("#datepicker1").val(),
			proEnd:$("#datepicker").val(),
			mod:"mSubmit"
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|",2);
			if(a[0]==1){
				showPage("?func=project_view&ajax=true&pid="+$("#pidhid").val());
			}
		}
	});
}

function updateContract(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			mod:'updateContract',
			contract_code:$("#contract_code").val()
		},
		success: function(msg){
			showMessage(msg);
			showPage("?func=project_view&ajax=true&pid="+$("#pidhid").val());
		}
	});
}

function updateProject(){
	$("#updateCredit").modal('hide');
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			mod:'updateProject',
			credit:$("#update_credit").val()
		},
		success: function(msg){
			showMessage(msg);
			showPage("?func=project_view&ajax=true&mod=bussiness&pid="+$("#pidhid").val());
		},
		complete: function(xhr){
			$("#updateCredit").modal('hide');
		}
	});
}

function insertRevenue(){
	$("#insertRevenue").modal('hide');
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			mod:'pushReceived',
			amount:$("#revenue_amount").val(),
			desc:$("#revenue_desc").val()
		},
		success: function(msg){
			showMessage(msg);
			showPage("?func=project_view&ajax=true&mod=bussiness&pid="+$("#pidhid").val());
		},
		complete: function(xhr){
			$("#insertRevenue").modal('hide');
		}
	});
}

function taoDuan(){
	$.ajax({
		type: "POST",
		url: "?func=project_create&ajax=true",
		data: {
			projectParent:$("#projectParent").val(),
			projectName:$("#projectName").val(),
			projectStart:$("#projectStart").val(),
			projectDead:$("#projectDead").val(),
			projectContent:$("#projectContent").val(),
			projectContract:$("#projectContract").val(),
			groupLeader:$("#groupLeader").val(),
			uutien:$("#uutien").val(),
			groupMember:$("#groupMember").val(),
			uploadfile:$("#uploadfile").val()
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				window.location.hash = 'project_view/pid='+a[2];
			}
			else{
				$('input[type=submit]').attr('disabled',false);
				$('button[type=submit]').attr('disabled',false);
			}
		}
	});
}

function submitDuan(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			mod:"mComplete",
			pid:$("#pidhid").val(),
			uploadfile:$("#uploadfile").val()
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				showPage('?func=project_view&ajax=true&pid='+a[2]);
			}
		}
	});
}

function acceptDuan(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			mod:"accept"
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|",2);
			if(a[0]==1){
				showPage("?func=project_view&ajax=true&pid="+$("#pidhid").val());
			}
		}
	});
}

function updateDuan(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			mod:"mUpdate",
			percent:$("#percent").val()
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|",2);
			if(a[0]==1){
				showPage("?func=project_view&ajax=true&pid="+$("#pidhid").val());
			}
		}
	});
}

function groupDuan(){
	var posts = $("#group_project").serialize();
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: posts,
		success: function(msg){
			showMessageJson(msg);
		}
	});
}


function editDuan(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			projectContent:$("#textarea").val(),
			mod:"pUpdate"
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|",2);
			if(a[0]==1){
				showPage("?func=project_view&ajax=true&pid="+$("#pidhid").val());
			}
		}
	});
}

function groupProject(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: $("#group_project").serialize(),
		success: function(msg){
			showMessageJson(msg);
		}
	});
}

function acpDuan(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			mod:"acpProject"
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|",2);
			if(a[0]==1){
				showPage("?func=project_view&ajax=true&pid="+$("#pidhid").val());
			}
		}
	});
}

function dnyDuan(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			mod:"dnyProject"
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|",2);
			if(a[0]==1){
				showPage("?func=project_view&ajax=true&pid="+$("#pidhid").val());
			}
		}
	});
}

function projectFilter(){
	var arr = {
		tieude:$("#search_tieude").val(),
		nguoigiao:$("#search_nguoigiao").val(),
		ngaystart:$("#datepicker").val(),
		ngayend:$("#datepicker1").val(),
		status:$("#statusFilter").val()
	};
	build_hash(arr);
	$(window).trigger('hashchange');
}

function doSearchProject(){
	$.ajax({
		type: "POST",
		url: "?func=project_list&ajax=true",
		data: {
			search:"1",
			tieude:$("#search_tieude").val(),
			nguoigiao:$("#search_nguoigiao").val(),
			ngaystart:$("#datepicker").val(),
			ngayend:$("#datepicker1").val()
		},
		success: function(msg){
			$("#show-content").html(msg).fadeIn();
		}
	});
}

function commentProject(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			pid:$("#pidhid").val(),
			proComment:$("#proComment").val(),
			uploadfile:$("#uploadfilecmt").val(),
			mod:"reply"
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			$('input[type=submit]').attr('disabled',false);
			$('button[type=submit]').attr('disabled',false);
			showMessage(msg);
			showPage("?func=project_view&ajax=true&pid="+$("#pidhid").val());
		}
	});
}

function taoTask(){
	var proName = $("#subproName").val();
	if(proName == 0 || proName == "" || proName == "undefined" || proName == null){proName = $("#proName").val();}
	$.ajax({
		type: "POST",
		url: "?func=task_create&ajax=true",
		data: {
			taskName:$("#taskName").val(),
			taskType:$("#taskType").val(),
			proName:proName,
			receiver:$("#receiver").val(),
			parent:$("#parent").val(),
			taskStart:$("#datepicker1").val(),
			taskDead:$("#datepicker").val(),
			taskContent:$("#textarea").val(),
			uploadfile:$("#uploadfile").val()
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			$("#show-content").unblock();
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				window.location.hash = 'task_view/tid='+a[2];
			}
			else{
				$('input[type=submit]').attr('disabled',false);
				$('button[type=submit]').attr('disabled',false);
			}
		}
	});
}

function editTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			mod:"editTask",
			taskStart:$("#datepicker1").val(),
			taskDead:$("#datepicker").val(),
			uploadfile:$("#uploadfile").val()
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				showPage("?func=task_view&ajax=true&tid="+$("#tidhid").val());
			}
			else{
				$('input[type=submit]').attr('disabled',false);
				$('button[type=submit]').attr('disabled',false);
			}
		}
	});
}

function changeUserTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			mod:"changeUser",
			receiver:$("#receiver").val()
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				showPage("?func=task_view&ajax=true&tid="+$("#tidhid").val());
			}
		}
	});
}

function editTaskContent(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			mod:"editTaskContent",
			taskContent:$("#textarea").val()
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				showPage("?func=task_view&ajax=true&tid="+$("#tidhid").val());
			}
			else{
				$('input[type=submit]').attr('disabled',false);
				$('button[type=submit]').attr('disabled',false);
			}
		}
	});
}

function huyTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			mod:"huyTask"
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				window.location.hash = 'task_list';
			}
		}
	});
}

function update_task_project(){
	$('.modal.in').modal('hide');
	setTimeout(function(){
		var posts = $("#form_update_tproject").serialize();
		$.ajax({
			type: "POST",
			url: "?func=task_ajax&ajax=true",
			data: posts,
			success: function(msg){
				showMessageJson(msg);
				showPage(currentLink);
			}
		});
	},1000);
}

function acceptTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			mod:"accept"
		},
		success: function(msg){
			showMessage(msg);
			showPage("?func=task_view&ajax=true&tid="+$("#tidhid").val());
		}
	});
}

function denyTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			mod:"deny"
		},
		success: function(msg){
			showMessage(msg);
			showPage("?func=task_view&ajax=true&tid="+$("#tidhid").val());
		}
	});
}

function reopenTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			mod:"reopen"
		},
		success: function(msg){
			showMessage(msg);
			showPage("?func=task_view&ajax=true&tid="+$("#tidhid").val());
		}
	});
}

function deleteTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			mod:"deletet"
		},
		success: function(msg){
			showMessage(msg);
			window.location.hash = 'task_list';
		}
	});
}

function updateTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			mod:"mUpdate",
			percent:$("#percent").val()
		},
		success: function(msg){
			showMessage(msg);
			showPage("?func=task_view&ajax=true&tid="+$("#tidhid").val());
		}
	});
}

function submitTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			uploadfile:$("#uploadfile").val(),
			mod:"mComplete"
		},
		success: function(msg){
			showMessage(msg);
			showPage("?func=task_view&ajax=true&tid="+$("#tidhid").val());
		}
	});
}

function commentTask(){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true&tid="+$("#tidhid").val(),
		data: {
			taskComment:$("#taskComment").val(),
			uploadfile:$("#uploadfilecmt").val(),
			mod:"reply"
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			$('input[type=submit]').attr('disabled',false);
			$('button[type=submit]').attr('disabled',false);
			showMessage(msg);
			showPage("?func=task_view&ajax=true&tid="+$("#tidhid").val());
		}
	});
}

function build_hash(arr){
	var newhash = '';
	var hash = location.hash;
	hash = hash.replace( /^#/, '' );
	if(hash.indexOf('/') != -1){
		hash = hash.split('/');
		newhash += hash[0] + '/';
		for(var key in arr){
			newhash += key + '=' + encodeURIComponent(arr[key]) + '&';
		}
		if(hash[1].indexOf('&') != -1){
			var hash_2 = hash[1].split('&');
			for(i = 0 ; i < hash_2.length ; i++){
				var hash_3 = hash_2[i].split('=');
				if(newhash.indexOf(hash_3[0]) == -1){
					newhash += hash_3[0] + '=' + encodeURIComponent(hash_3[1]) + '&';
				}
			}
		}
		else{
			var hash_2 = hash[1].split('=');
			if(newhash.indexOf(hash_2[0]) == -1){
				newhash += hash_2[0] + '=' + encodeURIComponent(hash_2[1]) + '&';
			}
		}
	}
	else{
		newhash += hash + '/';
		for(var key in arr){
			newhash += key + '=' + encodeURIComponent(arr[key]) + '&';
		}
	}
	window.location.hash = newhash;
}

function taskFilter(){
	var arr = {
		taskType: $("#cvdrop").val(),
		tieude: $("#search_tieude").val(),
		nguoigiao: $("#search_nguoigiao").val(),
		nguoinhan: $("#search_nguoinhan").val(),
		status:$("#statusFilter").val()
	};
	build_hash(arr);
	$(window).trigger('hashchange');
}

function changePass(){
	$.ajax({
		type: "POST",
		url: "?func=usercp_ajax&ajax=true",
		data: {
			mChangeP:"1",
			oldpass:$("#oldpass").val(),
			newpass:$("#newpass").val(),
			newpass2:$("#newpass2").val()
		},
		success: function(msg){
			showMessage(msg);
			showPage('?func=usercp_view&ajax=true');
		}
	});
}

function changeInfo(){
	$.ajax({
		type: "POST",
		url: "?func=usercp_ajax&ajax=true",
		data: $("#changeInfo").serialize(),
		success: function(msg){
			showMessage(msg);
			showPage('?func=usercp_view&ajax=true');
		}
	});
}

function project_cust(){
	var posts = $("#project_cust").serialize();
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: posts,
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				showPage(currentLink);
			}
		}
	});
}

function track_verify(id){
	$.ajax({
		type: "POST",
		url: "?func=task_ajax&ajax=true",
		data: {
			mod:'track_verify',
			id:id
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
			if(getData.type == 'success'){
				showPage(currentLink);
			}
		}
	});
}

function track_delete(id){
	var r = confirm("Bạn có chắc chắn muốn xóa hình ảnh này!");
	if (r == true){
		$.ajax({
			type: "POST",
			url: "?func=task_ajax&ajax=true",
			data: {
				mod:'track_delete',
				id:id
			},
			success: function(msg){
				showMessageJson(msg);
				var getData = $.parseJSON(msg);
				if(getData.type == 'success'){
					showPage(currentLink);
				}
			}
		});
	}
}

function doSearchMsg(){
	$.ajax({
		type: "POST",
		url: "?func=usercp_msg&ajax=true",
		data: {
			search:"1",
			content:$("#search_content").val(),
			nguoigui:$("#search_nguoigui").val()
		},
		success: function(msg){
			$("#show-content").html(msg).fadeIn();
		}
	});
}

function writeMsg(){
	$.ajax({
		type: "POST",
		url: "?func=usercp_ajax&ajax=true",
		data: {
			Receiver:$("#Receiver").val(),
			mTitle:$("#mTitle").val(),
			mContent:$("#mContent").val(),
			uploadfile:$("#uploadfile").val(),
			Send:"1"
		},
		success: function(msg){
			showMessage(msg);
			window.location.hash = 'usercp_msgo';
		}
	});
}

function replyMsg(id){
	$.ajax({
		type: "POST",
		url: "?func=usercp_msgc&ajax=true",
		data: {
			msgId:id
		},
		success: function(msg){
			$("#show-content").html(msg).fadeIn();
		}
	});
}

function checkAllMsg(){
	var val = false;
	if($("#checkAll").is(':checked')){ val=true;}
	else{ val=false; }
	for(i = 1; i <= 10 ; i++){
		$("#msg"+i).attr('checked', val);
	}
}

function msgAction(){
	var act = $("#msgAction").val();
	var str = '';
	for(i = 1; i <= 10 ; i++){
		if(!isNaN($("#msg"+i+":checked").val())){
			str += $("#msg"+i+":checked").val()+"-";
		}
	}

	if(act=='markRead'){
		$.ajax({
			type: "POST",
			url: "?func=usercp_ajax&ajax=true",
			data: {
				mod:"msg_mark_read",
				msgList:str
			},
			success: function(msg){
				showMessageJson(msg);
				reload_page();
			}
		});
	}
	else if(act=='delete'){
		$.ajax({
			type: "POST",
			url: "?func=usercp_ajax&ajax=true",
			data: {
				mod:"msg_delete",
				msgList:str
			},
			success: function(msg){
				showMessageJson(msg);
				window.location.hash = 'usercp_msg';
			}
		});
	}
}

function doReport(){
	$.ajax({
		type: "POST",
		url: "?func=report_view&ajax=true",
		data: {
			reportType:$("#reportType").val(),
			reportTarget:$("#reportTarget").val(),
			reportYear:$("#reportYear").val(),
			reportMonth:$("#reportMonth").val()
		},
		success: function(msg){
			$("#show-content").html(msg).fadeIn();
		}
	});
}

function doReportRev(){
	$.ajax({
		type: "POST",
		url: "?func=report_revenue&ajax=true",
		data: {
			reportYear:$("#reportYear").val(),
			reportMonth:$("#reportMonth").val()
		},
		success: function(msg){
			$("#show-content").html(msg).fadeIn();
		}
	});
}

function createLine(){
	$.ajax({
		type: "POST",
		url: "?func=finance_ajax&ajax=true",
		data: {
			mod:'create_line',
			line_name:$("#line_name").val(),
			line_prefix:$("#line_prefix").val(),
			line_desc:$("#line_desc").val(),
			uynhiem:$("#uynhiem").val()
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			$('input[type=submit]').attr('disabled',false);
			$('button[type=submit]').attr('disabled',false);
			showMessage(msg);
			window.location.hash = 'finance_line';
		}
	});
}

function updateLine(id){
	$.ajax({
		type: "POST",
		url: "?func=finance_ajax&ajax=true",
		data: {
			mod:'update_line',
			line_id:id,
			uynhiem:$("#uynhiem").val()
		},
		success: function(msg){
			showMessage(msg);
			window.location.hash = 'finance_line';
		}
	});
}

function update_contract(id){
	$.ajax({
		type: "POST",
		url: "?func=finance_ajax&ajax=true",
		data: {
			mod:'update_contract',
			pay_id:id,
			contract:$("#contract").val()
		},
		success: function(msg){
			showMessageJson(msg);
			$("#update_contract").modal('hide');
			reload_page();
		}
	});
}

function update_project(id){
	$.ajax({
		type: "POST",
		url: "?func=finance_ajax&ajax=true",
		data: {
			mod:'update_project',
			pay_id:id,
			project:$("#project").val()
		},
		success: function(msg){
			showMessageJson(msg);
			$("#update_project").modal('hide');
			reload_page();
		}
	});
}

function delete_payment(id){
	var r=confirm("Are you Sure?");
	if (r==true){
		$.ajax({
			type: "POST",
			url: "?func=finance_ajax&ajax=true",
			data: {
				mod:'delete_payment',
				pid:id
			},
			success: function(msg){
				showMessage(msg);
				reload_page();
			}
		});
	}
}

function createItem(){
	var money = $("#dongia").val();
	money = money.replace(/,/g,"");
	var total = money * $("#soluong").val();
	var ttotal = parseInt($("#total").val()) + total;
	$.ajax({
		type: "POST",
		url: "?func=request_ajax&ajax=true",
		data: {
			mod:'additem',
			name:$("#name").val(),
			donvi:$("#donvi").val(),
			dongia:money,
			soluong:$("#soluong").val(),
			mota:$("#mota").val()
		},
		success: function(msg){
			$('.modal.in').modal('hide');
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				$("#dbdetail").find('tbody').append($('<tr id="st'+getData.itemcode+'">').append("<td>"+$("#name").val()+"</td><td>"+$("#donvi").val()+"</td><td>"+$("#soluong").val()+"</td><td>"+$("#dongia").val()+"</td><td>"+toCurrency(total)+"</td><td><a href='javascript:;' onClick=\"rmItem('"+getData.itemcode+"');\">Xóa</a></td>"));
				$("#dtdb").val($("#dtdb").val()+"||"+getData.itemcode+"-"+$("#soluong").val()+"-"+total);
				$("#total").val(ttotal);
				$("#bangso").val(toCurrency(ttotal));
				$.ajax({
					type: "POST",
					url: "?func=request_ajax&ajax=true",
					data: {
						mod:'currency2text',
						amount:ttotal
					},
					success: function(msg){
						$("#bangchu").val(msg);
					}
				});
			}
		}
	});
}

function createReturnItem(){
	$("#dbdetail").find('tbody').append($('<tr>').append("<td><input type=text style='width:100%;' name='item_name[]' value=''></td><td><input type=text name='item_amount[]' value=''></td><td><input type=text name='item_price[]' value=''></td>"));
}

function rmItem(id){
	var str = $("#dtdb").val();
	var newstr = "";
	var arr = str.split("||");
	var flag = 0;
	var col;
	for(var a = 0; a < arr.length ; a++){
		if(arr[a]!=''){
			col = arr[a].split("-");
			if(col[0] != id){ newstr += "||"+arr[a];}
			else{
				var ttotal = parseInt($("#total").val()) - col[2];
				$("#total").val(ttotal);
				$("#bangso").html(toCurrency(ttotal));
				$.ajax({
					type: "POST",
					url: "?func=request_ajax&ajax=true",
					data: {
						mod:'currency2text',
						amount:ttotal
					},
					success: function(msg){
						$("#bangchu").html(msg);
					}
				});
			}
		}
	}
	$("#st"+id).fadeOut();
	$("#dtdb").val(newstr);
}

function createRequest(){
	$.ajax({
		type: "POST",
		url: "?func=request_ajax&ajax=true",
		data: {
			mod:'create',
			line:$("#line_id").val(),
			task:$("#task_c").val(),
			detail:$("#dtdb").val(),
			reason:$("#reason").val(),
			deadline:$("#deadline").val()
		},
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				window.location.hash = 'request_list';
			}
			else{
				$('input[type=submit]').attr('disabled',false);
				$('button[type=submit]').attr('disabled',false);
			}
		}
	});
}

function verifyReq(code){
	$.ajax({
		type: "POST",
		url: "?func=request_ajax&ajax=true",
		data: {
			mod:'verify',
			cd:code
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				showPage('?func=request_view&id='+getData.id+'&ajax=true');
			}
		}
	});
}

function verifyReturn(id){
	$.ajax({
		type: "POST",
		url: "?func=request_ajax&ajax=true",
		data: {
			mod:'verifyReturn',
			ret_id:id
		},
		success: function(msg){
			showMessageJson(msg);
			showPage(currentLink);
		}
	});
}

function attachPTU(){
	var datas = new Array();
	$("input[name='reqRes']:checked").each(function(i) {
		datas.push($(this).val());
	});
	$.ajax({
		type: "POST",
		url: "?func=finance_ajax&ajax=true",
		data: {
			mod:"link2ptc",
			ptc:$("#ptc").val(),
			str:datas
		},
		success: function(msg){
			showMessage(msg);
			var a = msg.split("|");
			if(a[0]==1){
				showPage('?func=finance_view&id='+$("#ptc").val()+'&ajax=true');
			}
		}
	});
}

function deletePTU(code){
	var r=confirm("Are you Sure?");
	if (r==true){
		$.ajax({
			type: "POST",
			url: "?func=request_ajax&ajax=true",
			data: {
				mod:'delete',
				cd:code
			},
			success: function(msg){
				showMessage(msg);
				var a = msg.split("|");
				if(a[0]==1){
					reload_page();
				}
			}
		});
	}
}

function markChiPTC(){
	$.ajax({
		type: "POST",
		url: "?func=request_ajax&ajax=true",
		data: {
			mod:'markchi',
			ptu:$("#reqid").val()
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				showPage('?func=request_view&id='+$("#reqid").val()+'&ajax=true');
			}
		}
	});
}

function markCompletePTC(){
	$.ajax({
		type: "POST",
		url: "?func=request_ajax&ajax=true",
		data: {
			mod:'markcom',
			ptu:$("#reqid").val()
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				showPage('?func=request_view&id='+$("#reqid").val()+'&ajax=true');
			}
		}
	});
}

function doSearchReq(){
	window.location.hash = 'request_list/type='+$('#search_type').val()+'&search='+$("#search_tieuchi").val()+'&search_u='+$("#search_user").val()+'&search_line='+$("#search_line").val();
}

function doSearchReqRev(){
	window.location.hash = 'request_list_review/type='+$('#search_type').val()+'&search='+$("#search_tieuchi").val()+'&search_u='+$("#search_user").val()+'&search_line='+$("#search_line").val();
}

function doFilterReq(){
	if($("#filter_from").val() != "" && $("#filter_to").val() != ""){
		var arr = {
			mod:'request_filter',
			from:$("#filter_from").val(),
			to:$("#filter_to").val(),
			status:$("#filter_status").val()
		};
		build_hash(arr);
		$(window).trigger('hashchange');
	}
	else{ toastr.error('Vui lòng chọn ngày tháng');}
}

function doSearchPay(){
	window.location.hash = 'finance_list/tieuchi='+$("#search_tieuchi").val()+'&ngay='+$("#search_ngay").val();
}

function doSearchPayPTU(){
	$.ajax({
		type: "POST",
		url: "?func=request_ajax&ajax=true",
		data: {
			mod:"searchpay",
			ptu:$("#reqid").val(),
			tieuchi:$("#search_tieuchi").val(),
			mapc:$("#search_code").val()
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				$("#pay_result").html(getData.html).fadeIn();
			}
		}
	});
}

function doSearchPTU(){
	$.ajax({
		type: "POST",
		url: "?func=finance_ajax&ajax=true",
		data: {
			mod:"searchptu",
			tieuchi:$("#search_tieuchi").val(),
			maptu:$("#search_code").val()
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				$("#ptu_result").html(getData.html).fadeIn();
			}
		}
	});
}

function attPay2Ptu(){
	var datas = new Array();
	$("input[name='payRes']:checked").each(function(i) {
		datas.push($(this).val());
	});
	$.ajax({
		type: "POST",
		url: "?func=request_ajax&ajax=true",
		data: {
			mod:"att2ptu",
			ptu:$("#reqid").val(),
			str:datas
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				showPage('?func=request_view&id='+$("#reqid").val()+'&ajax=true');
			}
		}
	});
}

function addLuong(id){
	$.ajax({
		type: "POST",
		url: "?func=salary_ajax&mod=insertSalary",
		data: {
			sa_line:$("#salary_name").val(),
			sa_amnt:$("#salary_amnt").val(),
            uid:id
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				showPage('?func=salary_view&ajax=true&id='+id);
			}
		}
	});
}

function deleteSalary(sid){
    $.ajax({
		type: "POST",
		url: "?func=salary_ajax&mod=deleteSalary",
		data: {
			said:sid
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
            if(getData.type=='success'){
				$("#r"+sid).fadeOut("slow");
			}
		}
	});
}

function exportSalary(){
	$.ajax({
		type: "POST",
		url: "?func=salary_ajax",
		data: {
			mod:'export'
		},
		success: function(msg){
			alert(msg);
		}
	});
}

function searchSalary(){
	window.location.hash = 'salary_list/month='+$("#sal_month").val()+'&year='+$("#sal_year").val();
}

function searchSalaryView(id){
	window.location.hash = 'salary_view/id='+id+'&month='+$("#sal_month").val()+'&year='+$("#sal_year").val();
}

function searchSalaryViewNV(){
	window.location.hash = 'usercp_salary/month='+$("#sal_month").val()+'&year='+$("#sal_year").val();
}

function setProjectCredit(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax",
		data: {
			mod:'setProjectCredit',
			pid:$("#pidhid").val(),
			pCredit:$("#pCredit").autoNumericGet(),
			pProfitCredit:$("#pProfitCredit").autoNumericGet()
		},
		success: function(msg){
			showMessage(msg);
		}
	});
}

function setProjectCredit2(){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax",
		data: {
			mod:'setProjectCredit2',
			pid:$("#pidhid").val(),
			pLine:$("#project_line").val(),
			pCredit:$("#pCredit").autoNumericGet(),
			pTotalProfit:$("#pTotalProfit").autoNumericGet(),
			pProfitCredit:$("#pProfitCredit").autoNumericGet()
		},
		success: function(msg){
			showMessage(msg);
		},
		complete: function(xhr){
			reload_page();
			setTimeout(setPercentCredit2,3000);
		}
	});
}

function setPercentCredit(){
	var list = new Array();
	$("input[name^=pPercentCredit]").each(function(){
		list.push(this.value);
	});
	$.ajax({
		type: "POST",
		url: "?func=project_ajax",
		data: {
			mod:'setPercentCredit',
			pid:$("#pidhid").val(),
			pPercentCredit:list
		},
		success: function(msg){
			showMessage(msg);
		}
	});
}

function setPercentCredit2(){
	var data = $("#percent-credit").serialize();
	$.ajax({
		type: "POST",
		url: "?func=project_ajax",
		data: data,
		success: function(msg){
			showMessage(msg);
			reload_page();
		}
	});
}

function pushSalary(){
	var r=confirm("Are you Sure?");
	if (r==true){
		$.ajax({
			type: "POST",
			url: "?func=project_ajax",
			data: {
				mod:'pushSalary',
				pushTime:$("#pushMonth").val()+'/1/'+$("#pushYear").val(),
				pid:$("#pidhid").val()
			},
			success: function(msg){
				showMessage(msg);
				showPage(currentLink);
			}
		});
	}
}

function push_salary(){
	$.ajax({
		type: "POST",
		url: "?func=ptype_ajax",
		data: {
			mod:'push_salary',
			push_time:$("#pushMonth").val()+'/1/'+$("#pushYear").val(),
			project:$("#pidhid").val()
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
			if(getData.type == 'success'){
				setTimeout(reload_page, 1000);
			}
		},
		complete: function(xhr){
			$("#push_salary").modal('hide');
		}
	});
}

function more_salary(){
	var data = $("#more_user").serialize();
	$.ajax({
		type: "POST",
		url: "?func=ptype_ajax",
		data: data,
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
			if(getData.type == 'success'){
				setTimeout(reload_page, 1000);
			}
		},
		complete: function(xhr){
			$("#more_salary").modal('hide');
		}
	});
}

function del_user_salary(id){
	var r=confirm("Are you Sure?");
	if (r==true){
		$.ajax({
			type: "POST",
			url: "?func=ptype_ajax",
			data: {
				mod:'del_user_salary',
				psal_id:id,
				project:$("#pidhid").val()
			},
			success: function(msg){
				showMessageJson(msg);
				var getData = $.parseJSON(msg);
				if(getData.type == 'success'){
					setTimeout(reload_page, 1000);
				}
			}
		});
	}
}

function removePushSalary(timePush){
	var r=confirm("Are you Sure?");
	if (r==true){
		$.ajax({
			type: "POST",
			url: "?func=project_ajax",
			data: {
				mod:'removePushSalary',
				timePush:timePush,
				pid:$("#pidhid").val()
			},
			success: function(msg){
				showMessage(msg);
				showPage(currentLink);
			}
		});
	}
}

function setFormulas(){
	var listValue = new Array();
	var listName = new Array();
	$("input[name^=formulas]").each(function(){
		listValue.push(this.value);
		listName.push(this.id);
	});
	$.ajax({
		type: "POST",
		url: "?func=salary_ajax",
		data: {
			mod:'setFormulas',
			listName:listName,
			listValue:listValue
		},
		success: function(msg){
			showMessageJson(msg);
		}
	});
}

function setTechnicalPrices(){
	var listValue = new Array();
	var listKTValue = new Array();
	var listId = new Array();
	$("input[name^=price]").each(function(){
		listValue.push(this.value);
		listId.push((this.id).replace('row',''));
	});
	$("input[name^=ktprice]").each(function(){
		listKTValue.push(this.value);
	});
	$.ajax({
		type: "POST",
		url: "?func=finance_technical_ajax",
		data: {
			mod:'setTechnicalPrices',
			listId:listId,
			listValue:listValue,
			listKTValue:listKTValue
		},
		success: function(msg){
			showMessageJson(msg);
		}
	});
}

function techFilter(){
	var arr = {
		date_start:$("#date_start").val(),
		date_end:$("#date_end").val()
	};
	build_hash(arr);
	$(window).trigger('hashchange');
}

function pushTechSalary(type){
	$.ajax({
		type: "POST",
		url: "?func=finance_technical_ajax",
		data: {
			mod:'pushTechSalary',
			type:type
		},
		success: function(msg){
			showMessageJson(msg);
		}
	});
}

function upload_req_file(code){
	$('.modal.in').modal('hide');
	setTimeout(function(){
		$.ajax({
			type: "POST",
			url: "?func=request_ajax&ajax=true",
			data: {
				mod: 'uploadReqFile',
				cd: code,
				file:$("#uploadfile").val()
			},
			success: function(msg){
				showMessageJson(msg);
				showPage(currentLink);
			}
		});
	},1000);
}

function QToanToggle(pid){
	$.ajax({
		type: "POST",
		url: "?func=project_ajax&ajax=true",
		data: {
			mod: 'QToanToggle',
			pid: pid
		},
		success: function(msg){
			showMessageJson(msg);
			showPage(currentLink);
		}
	});
}

function createReturn(){
	var posts = $("#return-form").serialize();
	$.ajax({
		type: "POST",
		url: "?func=return_create&ajax=true",
		data: posts,
		beforeSend: function (xhr) {
			$('input[type=submit]').attr('disabled',true);
			$('button[type=submit]').attr('disabled',true);
		},
		success: function(msg){
			showMessageJson(msg);
			var getData = $.parseJSON(msg);
			if(getData.type == 'success'){
				window.location.hash = 'request_view/id=' + getData.request;
			}
			else{
				$('input[type=submit]').attr('disabled',false);
				$('button[type=submit]').attr('disabled',false);
			}
		}
	});
}

function attach_task(){
	$('.modal.in').modal('hide');
	setTimeout(function(){
		var posts = $("#form_attach_task").serialize();
		$.ajax({
			type: "POST",
			url: "?func=request_ajax&ajax=true",
			data: posts,
			success: function(msg){
				showMessageJson(msg);
				var getData = $.parseJSON(msg);
				if(getData.type == 'success'){
					showPage(currentLink);
				}
			}
		});
	},1000);
}